//
//  HNGiveAwayFlowerView.m
//  优学荟管理系统
//
//  Created by edz on 2017/11/14.
//  Copyright © 2017年 星道三好. All rights reserved.
//

#import "HNGiveAwayFlowerView.h"

@implementation HNGiveAwayFlowerView
{
    __weak IBOutlet UIView *_ContentView;
    __weak IBOutlet UIView *_View;
    __weak IBOutlet UITextField *_Number;
    UIViewController *_VC;
}

- (instancetype)initWithVC:(UIViewController *)VC Complete:(void (^)())Complete {
    
    self = [[NSBundle mainBundle] loadNibNamed:[HNGiveAwayFlowerView description] owner:nil options:nil][0];
    if (self) {
        
        _VC = VC;
        self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
        
        UIBlurEffect * blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
        UIVisualEffectView * effe = [[UIVisualEffectView alloc]initWithEffect:blur];
        effe.frame = [UIScreen mainScreen].bounds;
        effe.alpha = 0.6f;
        //把要添加的视图加到毛玻璃上
        [_VC.view addSubview:effe];
        [[UIApplication sharedApplication].keyWindow.rootViewController.view addSubview:self];
        
        _View.layer.shadowColor = [UIColor blackColor].CGColor;//shadowColor阴影颜色
        _View.layer.shadowOffset = CGSizeMake(0,0); //shadowOffset阴影偏移,x向右偏移4，y向下偏移4，默认(0, -3),这个跟shadowRadius配合使用
        _View.layer.shadowOpacity = 0.8;//阴影透明度，默认0
        _View.layer.shadowRadius = 2;//阴影半径，默认3
    }
    return self;
}

- (void)awakeFromNib {
    
    [super awakeFromNib];
    [_Number resignFirstResponder];
}

- (IBAction)CloseMine {
    
    
    [_VC.view.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
       
        if ([obj isKindOfClass:[UIVisualEffectView class]]) {
            
            [obj removeFromSuperview];
            *stop = YES;
        }
    }];
    [self removeFromSuperview];
}


- (IBAction)Sure:(UIButton *)sender {
    
    if (_Number.text.length <= 0 || [_Number.text isEqualToString:@"0"]) {
        
        [SVProgressHUD showErrorWithStatus:@"请输入红花数"];
        return;
    }
    
    self.SureAction ? self.SureAction(_Number.text):nil;
}
@end
